package org.tnaggs.project.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.tnaggs.project.model.Contact;
import org.tnaggs.project.repository.ContactRepository;
import org.tnaggs.project.repository.ConversionRepository;


public class LaxUserDetailsService implements UserDetailsService {

	@Autowired
	private ContactRepository contactRepo;
	
	@Autowired 
	private ConversionRepository roleRepo;
	
	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		Contact contact = contactRepo.findByName(username);
		
		return new ContactUser(
				contact, roleRepo.getRole(contact.getRoleID()));
	}

	public ContactRepository getContactRepo() {
		return contactRepo;
	}

	public void setContactRepo(ContactRepository contactRepo) {
		this.contactRepo = contactRepo;
	}

	public ConversionRepository getRoleRepo() {
		return roleRepo;
	}

	public void setRoleRepo(ConversionRepository roleRepo) {
		this.roleRepo = roleRepo;
	}

}
